<template>
  <div class="app-container calendar-list-container">

    <!-- 查询-->
    <el-card>
      <div class="block">
        <span style="color:gray; font-size:16px"> 对账时间: </span>
        <el-date-picker type="datetimerange"
                        v-model="ReconciliationsQuery.timeInterval"
                        :picker-options="pickerOptions"
                        :default-time="['00:00:00', '00:00:00']"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        size="mini"
                        align="right">
        </el-date-picker>
        <el-button size="mini"
                   class="filter-item"
                   type="primary"
                   icon="el-icon-search"
                   @click="getList">检索</el-button>
      </div>
    </el-card>

    <el-card>
      <el-button size="medium"
                 type="primary">机构端</el-button>
      <!-- 查询结果 -->
      <div style="margin-bottom: 10px"></div>
      <el-table size="small"
                :data="list"
                v-loading.body="listLoading"
                id="reconciliationsTable"
                element-loading-text="加载中"
                border
                fit
                highlight-current-row>

        <el-table-column align="center"
                         min-width="100"
                         prop="source">
        </el-table-column>

        <el-table-column align="center"
                         label="总笔数"
                         prop="totalCount">
        </el-table-column>
        <el-table-column align="center"
                         label="总金额"
                         prop="totalFee">
        </el-table-column>
      </el-table>
    </el-card>
    <div style="margin-bottom: 10px"></div>

    <el-card>
      <el-button size="medium"
                 type="primary">各渠道</el-button>
      <div style="margin-bottom: 10px"></div>
      <!-- 查询结果 -->
      <el-table size="small"
                :data="listChannel"
                v-loading.body="listChannelLoading"
                id="reconChannelTable"
                element-loading-text="加载中"
                border
                fit
                highlight-current-row>

        <el-table-column align="center"
                         min-width="100"
                         prop="source">
        </el-table-column>

        <el-table-column align="center"
                         label="总金额">
          <el-table-column align="center"
                           label="平台"
                           prop="totalPlatModeFee"></el-table-column>
          <el-table-column align="center"
                           label="机构"
                           prop="totalOrgModeFee"></el-table-column>
        </el-table-column>

        <el-table-column align="center"
                         label="总笔数">
          <el-table-column align="center"
                           label="平台"
                           prop="totalPlatModeCount"></el-table-column>
          <el-table-column align="center"
                           label="机构"
                           prop="totalOrgModeCount"></el-table-column>
        </el-table-column>

        <el-table-column align="center"
                         label="结果">
          <template slot-scope="scope">
            <div>{{ scope.row.totalPlatModeFee == scope.row.totalOrgModeFee && scope.row.totalPlatModeCount == scope.row.totalOrgModeCount ? "帐平" : "帐不平"}}</div>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

  </div>
</template>

   <script>
import { getOrgResult, getChannelResult } from '@/api/Reconciliations'
// import debounce from 'lodash/debounce'
export default {
  name: 'reconciliationsResult',
  data() {
    return {

      listChannel: null,
      ReconciliationsQuery: {
        timeInterval: [new Date().setHours(0, 0, 0, 0) - 24 * 60 * 60 * 1000, new Date(new Date().setHours(0, 0, 0, 0)-1)],
        orgId: this.orgId
      },
      listLoading: false,
      listChannelLoading: false,
      list: null,
      pickerOptions: {

        shortcuts: [{
          text: '前天',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24)
            end.setTime(start.getTime() - 3600 * 1000 * 24 * 1) * 2
            picker.$emit('pick', [start, end])
          }
        },
        {
          text: '昨天',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 1)
            picker.$emit('pick', [start, end])
          }
        },
        {
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      this.listChannelLoading = true
      getOrgResult(this.ReconciliationsQuery).then(res => {
        this.list = res.data.list
        this.listLoading = false
      })
      getChannelResult(this.ReconciliationsQuery).then(res => {
        this.listChannel = res.data.list
        this.listChannelLoading = false
      })
    }
  }

}
</script>

   <style>
</style>
